home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 58 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  19.6 KB

  1. From: mcorcora@ix.netcom.com (Marian Corcoran )
  2. Message-ID: <199601172346.PAA21222@ix9.ix.netcom.com>
  3. X-Original-Date: Wed, 17 Jan 1996 15:46:17 -0800
  4. Path: in2.uu.net!bounce-back
  5. Date: 18 Jan 96 00:09:31 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Organization: -
  8. Newsgroups: comp.std.c++
  9. Return-Path: <mcorcora@ix.netcom.com>
  10. Subject: STL FAQ, update 1/16/96- STL e-mail list started
  11. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  12.     iQBFAgUBMP2P0+EDnX0m9pzZAQG1fgF/eJHeIR+ftPsPsawIoXDVoF1LAOYaxdRR
  13.     j4VF+wGdz4OJljXKsF8lFT8RwUjN6hci
  14.     =gP7u
  15.  
  16. C++ STL FAQ
  17.    This FAQ deals with the containers, iterators,
  18. and algorithms sections of the C++ Standard, 
  19. Clauses 23, 24 and 25.
  20.  
  21. If you have any questions you had while working with the
  22. STL and answers you received or worked out, please
  23. submit them to me for inclusion. I will give you credit
  24. for it if you include your name. 
  25.  
  26. Thanks,
  27. Marian Corcoran
  28. mcorcora@ix.netcom.com
  29. Copyright (c) 1995, Marian Corcoran
  30. This may be freely distributed, but not sold. 
  31. No guarantees.
  32.  
  33. update 1/16/96
  34.  
  35. Article:
  36. 1.  Glass, Graham. "Extending STL." C++ Report, Jan, 1996.
  37.  
  38. 2.  New e-mail list for STL discussion started
  39.   To post to the list, send email to
  40.  
  41.   genstl@atext.com
  42.  
  43. To ask to be added or removed from the list, send email to
  44.  
  45.   genstl-request@atext.com
  46.  
  47. with the word "subscribe" or "unsubscribe" in the Subject line.
  48.  
  49. This mailing list is devoted to STL (the C++ Standard Template Library)
  50. and the style of generic programming it exemplifies.  Appropriate 
  51. topics
  52. for discussion include the following:
  53.  
  54. - The effective use of STL.
  55. - The design of STL.
  56. - Possible extensions to STL.
  57. - STL programming questions.
  58. - Language-related issues, e.g., language extensions to C++ or other 
  59. languages
  60.   that would make generic programming easier.
  61. - Traps and pitfalls in using STL.
  62. - Design principles, strategies, and techniques for producing libraries 
  63. of
  64.   generic software components.
  65. - Specifying and reasoning about generic algorithms (e.g.,
  66.   required properties of iterators).
  67. - Application areas to target for the development of their own 
  68. libraries
  69.   of generic software components.
  70. - Announcements of papers and other publications.
  71.  
  72. The following are NOT appropriate for this list:
  73.  
  74. - Flames
  75. - Questions that can be answered by reading Marian Corcoran's STL FAQ,
  76.   which is posted regularly to comp.lang.c++ and can also be obtained
  77.   at ftp://butler.hpl.hp.com/stl/stl.faq.
  78.  
  79. 3.  Whitepaper on using STL with VC++ 4
  80.   http://www.microsoft.com/devonly/visualc
  81.   
  82. update 12/1/95
  83.  
  84. 1. New Books and Articles:
  85.    Glass, Graham.  STL Primer.  Prentice-Hall, 1995.
  86.      Based on ObjectSpace Manual.
  87.    Musser, David.  STL Tutor and Reference.  Addison-Wesley, 1995.
  88.    Nelson, Mark.  C++ Programmer Guide to STandard Template
  89.       Library Programming. IDG Books, 1995.
  90.      Good introduction.  
  91.    Plauger, P.J.  Has an article on STL in C/C++ Users
  92.       Journal, Dec 1995.
  93. 2. Added questions 6 and onward in Q & A part.
  94.  
  95. 3. RogueWave STL to be included in Borland C++ Compiler.
  96.  
  97. 4. The following comes from one of my students in my STL course:
  98.    After managing to install the ObjectSpace STL<Toolkit> with the    
  99.    Watcom   
  100.    C++/C 10.5 compiler, I wrote notes on the subject in FAQ format.  
  101.    The experience was positive - the two work well together. 
  102.    I humbly hope that this may be of others who need to install this   
  103.    version of the STL under a compiler which is not Borland, MS, or 
  104. gnu,   
  105.    or on a platform other than DOS/Win or unix (I used Warp). 
  106.    I placed the ASCII text version of the faq in: 
  107.    ftp.netcom.com/pub/me/medina/C++/objectspace_and_watcom_faq.txt 
  108.    (with a web browser, place the string, "ftp://" ahead of that 
  109. address.) 
  110.    -- Sean Medina
  111. update 9/2/75
  112.    Two excellent articles have appeared on the STL
  113.  
  114. Dawes, Beman.  "You Can Count On It."  C/C++ Users 
  115.     Journal, July, 1995.  Excellent intro material.
  116. Zigmond, Dan. "Generic Programming and the C++ STL."
  117.     Dr. Dobb's Journal, August, 1995.  Another good
  118.     sample program.
  119.  
  120. Rogue-Wave will be providing the STL to the following
  121. vendors: HP, SGI, SunSoft, Siemens-Nixdorf
  122.  
  123. update 7/3/95
  124.    Started adding new sections on questions 
  125.  
  126. Of special note:  A major complaint about libraries that
  127. programmers have is that you don't get the source.  Well, 
  128. with STL, you get the source.  STL source is 
  129. also excellent code to study.  It is very well written code. 
  130.  
  131. CONTENTS
  132.  
  133. I have put together four articles for the STL FAQ:
  134.   I.    Sources 
  135.   II.   Questions
  136.   III.  References of STL (M. Corcoran).  
  137.   IV.   Report from Lockheed on their first experiences 
  138.         with STL.  
  139.   V.    On using MODENA by Edgar Crisostomo (along with some 
  140.         needs in education that he sees for STL)
  141.   VI.   Comparison of Modena and ObjectSpace by Mike Lindner. 
  142.  
  143. REQUEST FOR OTHER MATERIAL  If someone has other material 
  144. or experiences to include you may e-mail them to me and 
  145. I will add them.  Especially of interest would be 
  146. examples of STL that you may have developed as you 
  147. learn STL or industrial applications or porting 
  148. instructions for different platforms.  Please state 
  149. whether I may use your article in the FAQ and whether 
  150. I may use your name.
  151.  
  152. Marian
  153. ===============================================================
  154. PART I  SOURCES
  155.  
  156. 1.  Where does one get the STL?
  157.  
  158.     A. anonymous ftp via butler.hpl.hp.com 
  159.         works with Borland 4.5 and IBM
  160.         also includes something on hash tables 
  161.         not in STL by Bob Fraley bfhash.zip
  162.             and David Musser dmhash.zip
  163.            no support included
  164.         to use the public domain version 
  165.             of STL with BC4.5
  166.         Projects|Defines  and type __MINMAX_DEFINED
  167.         or use #define __MINMAX_DEFINED before
  168.         #include <iostream.h>
  169.  
  170.     B. STL++: Modena Software at 1-800-MODENA-1
  171.         works with Borland, IBM C Set++, Apogee, 
  172.             Visual C++ 2.0 (this last has some limitations.)
  173.         comes with tutorial, you can get the tutorial 
  174.                
  175.             separately (read this tutorial after A. Stevens 
  176.             and after playing with ObjectSpace examples.)
  177.  
  178.     C. STL<ToolKit>:ObjectSpace at 1-800-OBJECT-1
  179.         most C++ compilers
  180.         code is well documented
  181.           comes with tutorial with over 200 elementary 
  182.             examples that have just been placed in the 
  183.       public domain available
  184.       via anonymous ftp via butler.hpl.hp.com at 
  185.                 /STL/examples.Z or .zip for PC
  186.         These examples are a good place to start. 
  187.  
  188.  
  189.      D. libstdc++ (part of libg++):    Free Software Foundation
  190.         anonymous ftp via prep.ai.mit.edu and many other 
  191.         machines only some containers exist, but works with GNU 
  192. C++, 
  193.       and probably many other C++ compilers
  194.  
  195.      E.  RogueWave to include STL, coming out in first quarter, 1996
  196.  
  197. ===============================================================
  198. PART II  QUESTIONS
  199.  
  200. 1.  What are the iterators, containers, and algorithms 
  201. sections of the  STL (Standard Library)?
  202. A.  The STL has a is a data structures or container class 
  203. library that has been adopted into the language.  It 
  204. consists of three major components:
  205.     Containers or data structures
  206.         Iterators
  207.     Algorithms
  208.  
  209. 2.  What are containers?
  210. Containers include such things as vectors, lists, queues, 
  211. priority queues, stacks, maps, and sets.  In STL, 
  212. containers (data structures) are templatized.  For 
  213. example, the stack class may be used with integers, 
  214. doubles, and user defined types.
  215.  
  216. 3.  What are iterators?
  217. Iterators may be thought of as the key to STL, acting 
  218. as an intermediary between the algorithms and the 
  219. containers.  You are already familiar with the concept 
  220. of an iterator when you think of the pointer used to 
  221. traverse an array.  Iterators are objects in STL.  
  222. One may think of them as a finger moving across the 
  223. elements of a container.  The five categories of 
  224. iterators are:
  225.  
  226.    Random Access -> Bidirectional-> Forward -> Input
  227.                             -> Output
  228. 4.  How are iterators related to containers and
  229. algorithms?
  230. One may think of each container and each algorithm as 
  231. being associated with a certain iterator.  A vector has 
  232. a random access iterator, therefore it may use a random 
  233. access algorithms such as a sort.  A container may use 
  234. any algorithm associated with its iterator or any 
  235. algorithm associated with an iterator to the right of 
  236. it in the above diagram. Therefore a vector (random 
  237. access iterator) may use algorithms associated with 
  238. bidirectional, forward, input or output iterators.  
  239. Can a vector be used with the binary_search algorithm 
  240. (takes a forward iterator) ?  If we look at the diagram 
  241. above, forward is to the right of random access, 
  242. therefore we may use binary_search with a vector 
  243. container.  Can a vector be used with copy (takes an 
  244. input and an output iterator)?  Since input and output 
  245. are to the right of random access, vector may used 
  246. with copy.
  247.  
  248. There are quite a number of algorithms in STL, 
  249. including count(), copy(), replace( ), reverse( ), ...
  250. Just as each container is associated with a certain 
  251. iterator, each algorithm is also associated with a 
  252. certain iterator(s).
  253.  
  254. count( ) - input iterator
  255. copy ( ) - input and output iterator
  256. replace( ) - forward iterator
  257. reverse( ) - bidirectional iterator
  258.  
  259. 6.  I got the ObjectSpace examples and they don't work 
  260. with the HP STL.  I get an error message that there 
  261. is no Stl.h file.
  262.  
  263. A.  ObjectSpace compiled all the different files of the 
  264. STL together.  This is helpful when first learning 
  265. it.  However, later you will probably want to include 
  266. just the files you need.  
  267.      A rule of thumb here is to always include the algo.h 
  268. or algorith.h (latter for ObjectSpace) file and then 
  269. nclude the file with the container you are using:
  270.  
  271. list - list.h
  272. stack, queue, priority_queue - stack.h
  273. deque - deque.h
  274. vector - vector.h
  275. map - map.h
  276. multimap - multimap.h
  277. set - set.h
  278. multiset - multiset.h
  279.  
  280. 7.  When I try to use HP STL with Borland 4.5, 
  281. I get an error function min and max already 
  282. defined.  Why?
  283.  
  284. The functions min( ) and max( ) are already defined 
  285. in the stdlib.h file.  However, there is #ifdef to 
  286. compile them only if they are already not defined.  
  287. Therefore, you may place a __MINMAX_DEFINED  line in 
  288. your Project|Defines window of put the line 
  289. #define __MINMAX_DEFINE before the 
  290. #include <iostream.h>
  291.  
  292. 8.  Where is the code for the STL?  When I downloaded
  293. STL from the HP site, I only got header files.
  294.  
  295. The code for the STL is in the .h files
  296.  
  297. 9.  I hear the STL is extensible.  What does that mean?
  298. How will different vendors extend the STL?
  299.  
  300. Extensible means that one will be able to add algorithms,
  301. containers, and iterators to the STL.
  302. Joe Buck (jbuck@synopsis.com) writes:
  303. Rogue Wave is now giving a January 1996 date for STL
  304. inclusion.  See
  305.  
  306. http://www.roguewave.com/rwpav/products/stdlibwp.htm
  307.  
  308. for discussion of their plans for including STL support
  309. in their Tools.h++ class library.
  310.  
  311. Reading that paper, and looking at what ObjectSpace has
  312. done (see http://www.objectspace.com/products/stl/), it
  313. seems that vendors are making their own enhancements to
  314. the libraries, generally in the same direction: to make
  315. the library somewhat less low-level, to provide cleaner
  316. interfaces for the very common
  317.  
  318.     algorithm(container.begin(), container.end())
  319.  
  320. so that one can write something like algorithm(container)
  321. (in ObjectSpace's case) or container.algorithm() (in
  322. Rogue Wave's case).
  323.  
  324. Perhaps the committee should consider doing a little bit in
  325. this area, before every library vendor does it differently?
  326. It seems that there are fairly natural interfaces that could
  327. be provided to cover the common cases where a range that
  328. is the entire container is to be specified, where the user
  329. is thinking "sort the container" or "copy container A to
  330. container B".  If the committee doesn't provide them, they
  331. will still be there, based on what vendors are already
  332. doing, but they will be non-portable.
  333.  
  334.  
  335.  
  336.  
  337. ==============================================================
  338. PART III  REFERENCES
  339.  
  340. A. PERIODICALS
  341.     D. Jordan. ODMG Update: Collections in ODMG-93
  342.        Discusses ODMG and STD LIB.  C++ Report, June 1995
  343.     A. Koenig. File iterators. Journal of Object-oriented
  344.      Programming  (JOOPS), Nov/Dec 1994
  345.     A. Koenig. Generic iterators. JOOPS, Sept. 1994
  346.     A. Koenig. Templates and generic iterators.  
  347.     JOOPS, June 1994
  348.     A. Koenig. ? . January , 1995
  349.     D.R. Musser and A.A. Stepanov. Algorithm-oriented 
  350.        generic libraries.  Software-Practice and Experience, 
  351.        July 1994
  352.     N. Meyers. A New and Useful Template Technique: 
  353.        "Traits" C++ Report, June 1995
  354.     A.A. Stepanov and M.Lee.  The Standard Template 
  355.       Library. ISO Programming Language C++ Project. 
  356.       Doc. No. X3J16/94-0095, WG21/N0482, May 1994.  
  357.       (Look in HP's ftp for stl.doc, I believe). 
  358.        Although it is the 
  359.     "definitive" STL, it is not intro material. 
  360.     A. Stevens. He has an interview with Stepanov in
  361.       Dr. Dobb's Journal, March 1995.  This is an 
  362.       excellent conceptual introduction to the STL, 
  363.       also a good place to start.
  364.     A. Stevens.  The Standard Template Library 
  365.        (with some code) in his column, Dr. Dobb's Journal, 
  366.        April 1995.  Also good intro material.
  367.     B. Stroustrup. Making a vector fit for a standard. 
  368.         C++ Report, Oct. 1994. intermediate level 
  369.         material. Stroustrup made some important 
  370.         contributions to the design of STL, discussed 
  371.         here.
  372.     M.J. Vilot. An introduction to the standard template
  373.      library.  C++ Report, Oct 1994. You might want to read 
  374.     Stevens and Dawes first.
  375.     Also see 
  376.     http://www.cs.rpi.edu/~musser/STL.html
  377.     This material is also available via anonymous ftp
  378.        ftp.cs.rpi.edu in directory pub/STL the file 
  379.     STL-info.ps.Z
  380.      includes STD LIB Online Algorithm Reference 
  381.       by R. Cook, 
  382.     D. Musser, and K Zalewski with examples.
  383.     See ObjectSpace examples first.
  384.  
  385.   B.  STL Web Pages - "Newbie" guide
  386.     http://weber.u.washington.edu/~bytewave/STL.html
  387.    1.  Intro material including Stepanov Speaks on 
  388.        STD LIB in C++     (M. Corcoran),
  389.    2.  Dr. Dobbs article (A. Stevens), STD LIB newbie 
  390.        notes (M. Khan),
  391.    3. STD LIB by Stepanov & Lee, STD LIB files, and 
  392.       ANSI C++ Draft (HTML version)
  393.  
  394.  
  395. ==============================================================
  396. PART IV. EXPERIENCES FROM LOCKHEED
  397.  
  398. We've just obtained STL<ToolKit> for use with our HP 
  399. cfront compiler and the Softbench development 
  400. environment. Here are the first impressions & observations:
  401.  
  402. Apparently ObjectSpace doesn't routinely deliver 4mm DAT 
  403. tapes and added $25 to do it. The tape we recieved was 
  404. DOA (unreadable) but the ObjectSpace support folks quickly 
  405. e-mailed the TAR-file and we were in bussiness. We did 
  406. not experience the problems reported by Mike Linder 
  407. contacting the ObjectSpace people. The above problem w
  408. as solved within two hours.
  409.  
  410. Our experience with installing and building the 
  411. libraries supports Mike Linder's observations. 
  412. Good job here by the vendor.
  413.  
  414. Compiling with the debug option (-g) resulted in many 
  415. warnings similar **to the following:
  416.  
  417. CC: "release1.C", line 28: warning: 
  418. debug.emit_type_entry:typedef node has no 
  419. symid_ptr: vector <X*> ::size_type (187)
  420. CC: "release1.C", line 28: warning: 
  421. debug.emit_type_entry:typedef node 
  422. **has no symid_ptr: vector <X*> ::const_reference (187)
  423.  
  424. The executable does run and the debugger still works, 
  425. however.
  426.  
  427. Note that the person evaluating STL<ToolKit> is 
  428. not an experienced C++ programmer and is proceding 
  429. on the strength of a C++ class. His first impressions 
  430. of the ObjectSpace documentation are favorable and 
  431. he was able to write a simple program from a 
  432. standing-start in a few hours. We also have the 
  433. documentation from HPs public-domain STD LIB. 
  434. I'll keep you posted.
  435.  
  436. ===============================================================
  437. PART V. ON USING MODENA at SIEMENS-ROLM
  438.  
  439.    We use Modena STL++ v2.0 - they respond fairly 
  440. quickly to our needs, they add bug fixes or compiler 
  441. support for our Unixware 2.0 SDK C++ compiler, and 
  442. they answer our many technical questions.
  443.  
  444. The STD LIB++ Manual has a "Files" Heading at the top 
  445. of each component description, and that is all that 
  446. should be explicitly #included to use that component 
  447. (mutual independence).
  448.  
  449. When I #include <vector.h>, it pulls in all the other 
  450. dependent includes.  It is not explicitly stated, but 
  451. for C-like arrays, you #include <algobase.h>.
  452.  
  453. There are minor problems, I will report to Modena 
  454. (example: hashfun.h has non-template function 
  455. _definitions_, so you get multiply defined, when 
  456. used over several translation units.   To improve 
  457. the ability (for us) to specify manual template 
  458. instantiation, it would be nice if they factor out 
  459. the non-inline template definitions into another file.
  460.  
  461. EDUCATIONAL HINTS
  462. A discussion of build issues would be useful.  Especially 
  463. since STL template code can have really obscure 
  464. compiler messages with todays compiler technology.  
  465. There are also issues with debugging template code.
  466.  
  467. A discussion of when to pass container by reference, 
  468. versus passing iterators would be useful.
  469.  
  470. Edgar Crisostomo    408-492-6528, 
  471. edgar@clipper.robadome.com
  472. Systems Software, 
  473. Siemens Rolm Communications, Inc. FAX 408-492-3305  
  474.  
  475. =============================================================
  476. PART VI
  477. COMPARISON OF MODENA AND OBJECTSPACE 
  478.  
  479. I just bought STL++ from Modena and 
  480. STL<toolkit> from ObjectSpace, for purposes of 
  481. comparison.  So far I have not had a chance to use 
  482. either extensively, but I have the following observations:
  483.  
  484. Modena was very helpful on the phone, and responded 
  485. quickly to whatever I called about.  The initial 
  486. floppy they sent me was bad, and they replaced it 
  487. overnight.  In every case but one technical question, 
  488. the person who answered the phone was able to do 
  489. everything I needed.  In the remaining case, I 
  490. received a call back within hours of my question.  
  491. I like their service.
  492.  
  493.  ObjectSpace had an operator, who directed me to the 
  494. one salesperson, who was always "out of the office" 
  495. when I called, and who was the only one who could 
  496. sell me the product (it took 5 days just to order 
  497. the product, because I couldn't get in touch with her).
  498.  
  499. Both products come as source, and you must build the 
  500. libraries yourself.  The documentation for doing this 
  501. from Modena was sketchy, and it wasn't until I called 
  502. tech support that I discovered I had to change some 
  503. files by hand to make them compile with my compiler 
  504. (which is one of the one's they advertise as working with).
  505.  
  506. ObjectSpace, on the other hand, has a neat little 
  507. config package that tests what your compiler can do, 
  508. and writes a header file which configures the code 
  509. to be correct for your compiler (lots of preprocessor 
  510. magic in them there header files).  It was a joy to use.
  511.  
  512. So far, the test programs I have compiled are much 
  513. smaller when I use the ObjectSpace libraries than 
  514. with the Modena libraries.  As I said, I have not 
  515. stressed either product, so these numbers may not 
  516. reflect use in an actual application.
  517.  
  518. As for conformance, ObjecSpace doesn't necessarily support 
  519. everything in STL, but only as much as they can 
  520. squeeze out of the compiler you give them to work 
  521. with.  Is that good or bad?
  522.  
  523. The ObjectSpace library claims to be "thread safe", 
  524. although I haven't tried that our yet.  Apparently 
  525. they have a wrapper class that behaves like a smart 
  526. pointer, but can be locked for reading or writing.  
  527. They also have some other platform independent thread 
  528. and mutex code.
  529.  
  530.   The Modena folks said their library is not 
  531. "thread safe", but only in one place, and they would 
  532. gladly show me how to modify the source to add that 
  533. feature.  One of my compiler vendors says they'll be 
  534. shipping Modena with their compiler soon, and their 
  535. version will be thread safe.
  536.  
  537. Modena includes some extra goodies, like hash tables 
  538. and an ANSI string class.
  539. ObjectSpace has added some features recently as well.
  540.  
  541. Mike Lindner
  542. mikel@attmail.com
  543. mpl@cmprime.attpls.com
  544. mpl@pegasus.att.com
  545. ---
  546. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  547.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  548.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  549.